﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using Traceability_Management.Domain;
using Traceability_Management.ErrorCode;
using Traceability_Management.Infrastructure.Interfaces;
using Traceability_Management.Read.Api.Application.Command.ProcessiingsWay;
using Traceability_Management.Read.Api.Application.Command.SlaughtsWay;

namespace Traceability_Management.Read.Api.Application.CommandHandler.ProcessiingsWay
{
    public class FirstProcessiongsCommandHandler : IRequestHandler<FirstProcessiongsCommand, ApiResult<Processiings>>
    {
        IBaseReponsitory<Processiings> Processiings;

        public FirstProcessiongsCommandHandler(IBaseReponsitory<Processiings> Processiings)
        {
            this.Processiings = Processiings;
        }

        public async Task<ApiResult<Processiings>> Handle(FirstProcessiongsCommand request, CancellationToken cancellationToken)
        {
            var Bachlist = await Processiings.GetQuery().FirstOrDefaultAsync(c => c.Rabit_Batch == request.Batch);
            if (Bachlist != null)
            {
                return new ApiResult<Processiings>
                {
                    Code = ApiEnum.Success,
                    Message = "加载成功了",
                    Data = Bachlist
                };
            }
            else
            {
                return new ApiResult<Processiings>
                {
                    Code = ApiEnum.Success,
                    Message = "请设置信息",
                };
            }
        }
    }
}
